new Vue({
    el: "#questionsApp",
    data: {
        questions:[], // 存储问题列表
        pageInfo:{}
    },
    methods: {
        loadMyQuestion(pageNum, pageSize) {
            let params = {'pageNum':pageNum, 'pageSize':pageSize}
            // "/portal/question/my?pageNum="+pageNum+"&pageSize="+pageSize
            axios.get("/portal/question/my?pageNum="+pageNum+"&pageSize="+pageSize, {params:params}).then(resp => {
                this.questions = resp.data.data.list
                this.pageInfo = resp.data.data
                console.log(this.questions)
                this.updateDuration()
                this.updateTagImage()
            })
        },
        updateDuration:function () {
            for (let i = 0; i < this.questions.length; i ++ ) {
                //创建问题时候的时间毫秒数
                let createtime = new Date(this.questions[i].createtime).getTime();
                //当前时间毫秒数
                let now = new Date().getTime();
                let duration = now - createtime;
                if (duration < 1000*60) { //一分钟以内
                    this.questions[i].duration = "刚刚";
                } else if (duration < 1000*60*60) { //一小时以内
                    this.questions[i].duration =
                        (duration/1000/60).toFixed(0)+"分钟以前";
                } else if (duration < 1000*60*60*24) {
                    this.questions[i].duration =
                        (duration/1000/60/60).toFixed(0)+"小时以前";
                } else {
                    this.questions[i].duration =
                        (duration/1000/60/60/24).toFixed(0)+"天以前";
                }
            }
        },
        updateTagImage(){
            for (let i = 0; i < this.questions.length; i ++ ) {
                let tags = this.questions[i].tags;
                if (tags) {
                    let tagImage = '/img/tags/'+tags[0].id+'.jpg';
                    console.log(tagImage);
                    this.questions[i].tagImage = tagImage;
                }
            }
        },
    },

    created() {
        this.loadMyQuestion(1, 8)
    }
})